package com.tanhua.server.controller;

import com.tanhua.model.domain.UserInfo;
import com.tanhua.server.interceptor.UserHolder;
import com.tanhua.server.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;
    //保存登录用户信息
    @PostMapping("/loginReginfo")
    public ResponseEntity<Object> loginReginfo(@RequestBody UserInfo userInfo) {

        //2、向userinfo中设置用户id
        userInfo.setId(UserHolder.getUserId());
        //3、调用service
        userInfoService.save(userInfo);
        return ResponseEntity.ok("ok");
    }

    //上传用户头像
    @PostMapping("/loginReginfo/head")
    public ResponseEntity<Object> head(MultipartFile headPhoto ){

        //设置用户id
        userInfoService.updateHead(headPhoto,UserHolder.getUserId());
        return ResponseEntity.ok("ok");
    }
}
